Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use caret for point to look up symbol #2440

Merged
merged 4 commits into from
May 3, 2024

Conversation

trbjo
Copy link
Contributor

@trbjo trbjo commented Apr 4, 2024

This commit changes the hover functionality such that the caret, not the beginning of the selection, is used for the symbol lookup. I use expand_to_... to navigate, and it's annoying that when I land on a symbol, I can't see the popup before the selection is empty again. I think this behavior is more natural and in accordance with what the user expects.

This commit changes the hover functionality such that the caret, not the
beginning of the selection, is used for the symbol lookup.
@jwortmann
Copy link
Member

Note that get_position is used by many other functions too. It wasn't me who wrote this line, but I could imagine that .begin() was used intentionally, instead of .b (caret position), even though the latter seems more intuitive. For example, if the caret is in the middle of a word, and you press Ctrl+D or use "expand selection" (Ctrl+Shift+A), then in both cases the caret will move to the end of the word (or block etc.). But this means that the caret position now actually points to the next character, which is likely a whitespace or a ( for example. This might be the reason why the begin of a selection was preferred over the actual caret position in this case.

I have tested with a few language servers, and all of them were smart enough to respond with the correct result even if the point (caret) is at the very end (i.e. actually behind) an identifier name. Based on this, I would assume that the proposed change should be acceptable, and I agree that it would feel more natural to always use the caret position. But I can't rule out whether there are any unintended side effects.

@predragnikolic
Copy link
Member

It make sense to use the caret position.

The previous logic was added in June 2020, and get_position was used in the following:
LspOpenLinkCommand
LspGotoCommand
LspHierarchyCommand
LspSymbolReferencesCommand
LspSymbolRenameCommand
LspExpandSelectionCommand
LspTextCommand

But I can't rule out whether there are any unintended side effects.

It is not easy to predict if it causes unintended side effects or not,
the best is to test all affected commands to at least confirm that it works as before.

@trbjo
Copy link
Contributor Author

trbjo commented Apr 20, 2024

I have used this code for the past 6 months or so, haven't noticed any changes. I've tested the commands you mentioned above, and I have not noticed any changed behavior. Is it possible to move forward with this? If not, would you be okay with a PR that makes this behavior optional, configurable with a boolean in the settings?

@predragnikolic
Copy link
Member

predragnikolic commented Apr 20, 2024

I'm more for the change you proposed.
I want to invest some time into testing it before merging.

I'll try to find the time next week.

Copy link

netlify bot commented Apr 22, 2024

Deploy Preview for sublime-lsp ready!

Name Link
🔨 Latest commit df47745
🔍 Latest deploy log https://app.netlify.com/sites/sublime-lsp/deploys/6628c13563250b000808c839
😎 Deploy Preview https://deploy-preview-2440--sublime-lsp.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@predragnikolic
Copy link
Member

I am starting to test this.

@trbjo can you give me more detailed steps on how to reproduce this case(or a short recording of your screen)?

I cannot really reproduce the behavior with the description from here:

I use expand_to_... to navigate, and it's annoying that when I land on a symbol, I can't see the popup before the selection is empty again.

@predragnikolic

This comment was marked as off-topic.

@predragnikolic
Copy link
Member

Before I would merge this, because the change makes sense.
But I would really try the usecase that you described here.

I use expand_to_... to navigate, and it's annoying that when I land on a symbol, I can't see the popup before the selection is empty again.

Like I said,
I could not really replicate this behavior that you decribled with the main branch.
Can you add some video recording of your case?

@predragnikolic
Copy link
Member

I haven't discovered that this PR breaks anything.
I also didn't discover/conclude what exact use case this PR solves.

So if anyone has an example that this PR solves, feel free to provide it.

@predragnikolic predragnikolic merged commit cdb2430 into sublimelsp:main May 3, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants